package com.qutan.app.quartz.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ning.http.client.AsyncHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

import javax.sql.DataSource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by pwy on 15/11/29.
 */
@Configuration
public class Config {

    /**
     * jackson setting
     * @return
     */
    @Bean
    ObjectMapper objectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return objectMapper;
    }

    /**
     * 应用 session
     * key : accessToken , value : userInfoDto
     * @return
     *//*
    @Bean
    HashMap<String, MerchantDto> appDtoSession() {
        HashMap<String, MerchantDto> appDtoMap = new HashMap<>();
        return appDtoMap;
    }*/

    @Bean
    NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource dataSource) {
        return new NamedParameterJdbcTemplate(dataSource);
    }

    @Bean
    AsyncHttpClient asyncHttpClient() {
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        return asyncHttpClient;
    }


    /**
     * 事件通知的线程池
     * @return
     */
    @Bean
    ExecutorService eventNotifyExecutorService() {
        return Executors.newFixedThreadPool(5);
    }


}
